package org.zhouhe.modules.industry.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.zhouhe.base.BaseAction;
import org.zhouhe.modules.industry.service.IndustryService;
import org.zhouhe.util.Constant;
import org.zhouhe.util.InitSystem;
import org.zhouhe.vo.Industry;

@SuppressWarnings("unchecked")
public class IndustryAction extends BaseAction {

	private static final long serialVersionUID = 3172977590976843309L;
	@Autowired
	private IndustryService industryService;
	private List<Industry> industryList;
	private Industry industry;
	// action methods:
	public String industryList() {
		industryList = (List<Industry>) servletContext.getAttribute(Constant.APPLICATION_KEY_INDUSTRY_LIST);
		return "industryList";
	}

	public String delete() {
		industryService.deleteIndustry(industry);
		InitSystem.reloadIndustry();
		return "delete";
	}

	public String update() {
		InitSystem.reloadIndustry();
		return "update";
	}
	
	public String save() {
		industryService.saveIndustry(industry);
		InitSystem.reloadIndustry();
		return "save";
	}
	
	public String moveUp(){
		industryService.move(getIndustry().getIndustryId(), true);
		InitSystem.reloadIndustry();
		return "moveUp";
	}
	
	public String moveDown(){
		industryService.move(getIndustry().getIndustryId(), false);
		InitSystem.reloadIndustry();
		return "moveDown";
	}
	
	// getter and setters:
	public void setIndustryList(List<Industry> industryList) {
		this.industryList = industryList;
	}
	public List<Industry> getIndustryList() {
		return industryList;
	}

	public void setIndustry(Industry industry) {
		this.industry = industry;
	}

	public Industry getIndustry() {
		return industry;
	}
}
